﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="../../script/ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
    <link href="../../style/css/tool-icon-16.css" rel="stylesheet" type="text/css" />
    <script src="../../script/ext/adapter/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="../../script/ext/adapter/jquery/ext-jquery-adapter.js" type="text/javascript"></script>
    <script src="../../script/ext/ext-all.js" type="text/javascript"></script>
    <script src="../../script/ext/src/locale/ext-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../script/jQuery/jquery_query-2_1_7.js" type="text/javascript"></script>
    <!---->
    <title>数据备份管理</title>
    <script type="text/javascript">
        /*获取模块编号*/
        var _modelid = jQuery.query.get("modelid");
        /*本地化资源*/
        Ext.BLANK_IMAGE_URL = "/script/ext/resources/images/s.gif";
        /*获取每页条数*/
        var _pageSize = 30; var cookiePageSize = parseInt(Ext.util.Cookies.get("pageSize")); if (cookiePageSize) { _pageSize = cookiePageSize; }

        Ext.onReady(function () {

            /*延时加载*/
            setTimeout(function () { Ext.get('loading').remove(); Ext.get('loading-mask').fadeOut({ remove: true }); }, 400);

            /*初始化快速提示*/
            Ext.QuickTips.init();

            /*将提示显示在form属性旁边*/
            Ext.form.Field.prototype.msgTarget = "qtip";

            /*创建下[每页行数]拉框*/
            var comboBox = new Ext.form.ComboBox({ width: 50, typeAhead: true, triggerAction: 'all', lazyRender: true, mode: 'local', title: "每页行数", value: _pageSize, store: new Ext.data.ArrayStore({ id: 0, fields: ['myId', 'displayText'], data: [[10, 10], [20, 20], [30, 30], [50, 50], [100, 100]] }), valueField: 'myId', displayField: 'displayText' });

            /*设置每页条数*/
            comboBox.on("select", function (combo, record, index) { Ext.util.Cookies.set("pageSize", record.id); _pageSize = record.id; /*重新加载数据源*/groupStore.load({ params: { start: 0, limit: _pageSize} }); });

            /*定义数据模型*/
            var Info = new Ext.data.Record.create([
            { name: 'BackTitle', mapping: 'BackTitle' },
            { name: 'BackTime', type: 'date', mapping: 'BackTime'}]);

            /*创建选择列模型*/
            var sm = new Ext.grid.CheckboxSelectionModel();

            /*定义列模型*/
            var cm = new Ext.grid.ColumnModel([sm,
            { id: 'addtime', header: '备份时间', dataIndex: 'BackTime', width: 140, sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d') },
            { id: 'title', header: '标题', dataIndex: 'BackTitle', width: 100, sortable: true}]);

            /*创建数据源*/
            var groupStore = new Ext.data.GroupingStore({
                proxy: new Ext.data.HttpProxy({ url: "server/DbBack/dbBack_List.aspx" }),
                reader: new Ext.data.JsonReader({ totalProperty: "Count", root: "List" }, Info),
                sortInfo: { field: 'BackTime', direction: 'DESC' }
            });

            /*创建信息窗格*/
            var grid = new Ext.grid.GridPanel({
                title: '数据备份',
                region: "north",
                height: 300,
                margins: "5 5 0 5",
                border: true,
                collapsible: true,
                frame: true,
                store: groupStore,
                autoExpandColumn: "title",
                loadMask: { msg: '正在努力的加载，请稍等片刻..' },
                view: new Ext.grid.GroupingView(),
                cm: cm,
                sm: sm,
                tbar: [{
                    iconCls: 'icon-add',
                    text: '创建备份',
                    value: 0,
                    handler: function (btn) {
                        Ext.Ajax.request({
                            url: 'server/DbBack/dbBack_Add.aspx',
                            success: function (response) {
                                Ext.Msg.alert('完成', '备份地址：<br/>' + response.responseText);
                            }
                        });
                    }
                }, {
                    ref: '../removeBtn',
                    iconCls: 'icon-del',
                    text: '删除备份',
                    disabled: true,
                    handler: function () {
                        Ext.MessageBox.confirm("确认提示", "确认删除所选数据备份？", function (btn) {
                            if (btn == "yes") {
                                var s = grid.getSelectionModel().getSelections();
                                var delR = new Array();
                                var delRid = new Array();
                                for (var i = s.length - 1; i >= 0; i--) {
                                    var r = s[i];
                                    if (r.get('ID') != undefined) { delRid.push(r.get('ID')); delR.push(r); }
                                }
                                Ext.Ajax.request({
                                    url: "server/notice/noticeDel.aspx?modelid=" + modelid,
                                    method: 'POST',
                                    params: { id: delRid },
                                    success: function (response) {
                                        var json = Ext.util.JSON.decode(response.responseText);
                                        if (json.success) {
                                            for (var i = 0; i < delR.length; i++) {
                                                if (json.ids.valueOf(delR[i].get('ID'))) { groupStore.remove(delR[i]) }
                                            }
                                            Ext.Msg.alert("提示", "已删除" + json.count + "行<br/>" + json.msg);
                                        } else {
                                            Ext.Msg.alert("错误", json.msg);
                                        }
                                    }
                                });
                            }
                        });
                    }
                }, {
                    ref: '../viewBtn',
                    iconCls: 'icon-view',
                    text: '还原备份',
                    disabled: true,
                    handler: function () {
                        Ext.MessageBox.confirm("确认提示", "确认还原所选数据备份？", function (btn) {
                            if (btn == "yes") {
                                var s = grid.getSelectionModel().getSelections();
                                window.open('server/notice/noticeDetail.aspx?id2=' + s[0].get("ID"));
                            }
                        });
                    }
                }],
                bbar: new Ext.PagingToolbar({ store: groupStore, pageSize: _pageSize, displayInfo: true, prependButtons: true, items: [comboBox], displayMsg: "本页显示第{0}条到第{1}条数据，共{2}条", emptyMsg: "暂无记录" })
            });

            /*服务器信息*/
            var serverInfo = new Ext.Panel({
                frame: true,
                margins: "5",
                region: "center",
                title: '服务器信息',
                loadMask: { msg: '正在努力的加载，请稍等片刻..' },
                autoLoad: { url: 'server/DbBack/serverInfo.aspx' }
            });

            /*创建页面布局*/
            var viewport = new Ext.Viewport({
                layout: 'border',
                items: [grid, serverInfo]
            });
            /*布局加载*/viewport.doLayout();
        });
    </script>
</head>
<body>
    <div id="loading-mask">
    </div>
    <div id="loading">
        <div class="loading-indicator">
            正在努力的加载...
        </div>
    </div>
</body>
</html>
